package com.tencreat.mq.message;

import com.tencreat.common.config.OpenIMConfig;
import com.tencreat.common.core.redis.RedisCache;
import com.tencreat.common.utils.bean.ActionMessage;
import com.tencreat.domain.im.dto.OpenIMTokenDTO;
import com.tencreat.domain.im.vo.OpenIMResultVo;
import com.tencreat.domain.im.vo.OpenIMTokenVo;
import com.tencreat.service.mall.IMallGoodsCutService;
import com.tencreat.service.im.OpenIMApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * 注册事件 - 消息处理类
 */
@Component
public class ActionMessageLogin implements IActionMessage {
    @Autowired
    OpenIMApi openIMApi;
    @Autowired
    RedisCache redisCache;

    @Override
    public void dealMessage(ActionMessage message) {

        /*String redisKey = OpenIMApi.IM_LOGIN_TOKEN + ":" + message.getUuid();
        // 登录后获取IM token
        if(!redisCache.hasKey(redisKey)){
            // 获取IM账号TOKEN
            OpenIMConfig openIMConfig = OpenIMConfig.getOpenIMConfig();
            OpenIMTokenDTO openIMTokenDTO = new OpenIMTokenDTO(openIMConfig.getSecret(), (Integer)message.getData(), message.getUuid().toString());
            OpenIMResultVo<OpenIMTokenVo> tokenResult = openIMApi.userToken(openIMTokenDTO);
            if(tokenResult.getErrCode() == 0){
                String token = tokenResult.getData().getToken();
                String expireTimeSeconds = tokenResult.getData().getExpireTimeSeconds();
                redisCache.setCacheObject(redisKey, token, Integer.parseInt(expireTimeSeconds)-3600, TimeUnit.SECONDS);
            }
        }*/
    }


}
